home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
-
-
- #include "system_headers.h"
-
- static APTR memmoretext0,memmoretext1,memmoretext2,memmoretext3,memmorelist;
-
- static APTR MemPool = NULL;
-
- __asm __saveds LONG memlist_dspfunc(register __a2 char **array, register __a1 struct MemoEntry *mementry, register __a0 struct Hook *hook)
- {
- if (mementry) {
- *array++ = mementry->mem_address;
- *array++ = mementry->mem_name;
- *array++ = mementry->mem_type;
- *array++ = mementry->mem_pri;
- *array++ = mementry->mem_lower;
- *array++ = mementry->mem_upper;
- *array++ = mementry->mem_attributes;
- *array = NULL;
- } else {
- *array++ = ESC "bAddress";
- *array++ = ESC "bln_Name";
- *array++ = ESC "bln_Type";
- *array++ = ESC "bln_Pri";
- *array++ = ESC "bmh_Lower";
- *array++ = ESC "bmh_Upper";
- *array++ = ESC "bmh_Attr";
- *array = NULL;
- }
- return(0);
- }
-
- struct Hook memlist_dsphook = {
- {NULL, NULL},
- (ULONG (* )())memlist_dspfunc,
- NULL, NULL
- };
-
- void FreeMemory (void)
- {
- MyFreePoolStructs(&MemPool, memtext, NULL, memlist);
- }
-
- int GetMemory (struct MemoEntry **first) {
- struct MemHeader *mem;
- struct MemoEntry *mementry,*previous = NULL;
-
- int memcnt = 0;
- *first = 0;
-
- mem = FIRSTMEMORY;
-
- if (!MemPool) MemPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
-
- if (clientstate) {
- if (SendDaemon ("GetMemList")) {
- while ((mementry = tbAllocPooled(MemPool, sizeof(struct MemoEntry))) \
- && (ReceiveDecodedEntry ((UBYTE *) mementry, sizeof (struct MemoEntry)))) {
- IsHex (mementry->mem_address, (long *) &mementry->mem_adr);
-
- if (! *first)
- *first = mementry;
- if (previous)
- previous->mem_next = mementry;
-
- memcnt++;
- previous = mementry;
- }
- }
- } else {
- while ((mem->mh_Node.ln_Succ != 0) && (mementry = tbAllocPooled(MemPool, sizeof(struct MemoEntry)))) {
- if (! *first)
- *first = mementry;
- if (previous)
- previous->mem_next = mementry;
-
- mementry->mem_adr = mem;
-
- _sprintf (mementry->mem_address, "$%08lx", mem);
- strncpy (mementry->mem_name, nonetest (mem->mh_Node.ln_Name), 20);
- strcpy (mementry->mem_type, GetNodeType (mem->mh_Node.ln_Type));
- _sprintf (mementry->mem_pri, "%4ld ", mem->mh_Node.ln_Pri);
- _sprintf (mementry->mem_lower, "$%08lx", mem->mh_Lower);
- _sprintf (mementry->mem_upper, "$%08lx", mem->mh_Upper);
- _sprintf (mementry->mem_attributes, " $%04lx", mem->mh_Attributes);
- memcnt++;
-
- previous = mementry;
- mem = (struct MemHeader *) mem->mh_Node.ln_Succ;
- }
- }
- return (memcnt);
- }
-
- void PrintMemory (char *filename) {
- int i=1;
- BPTR handle;
- struct MemoEntry *entryp = NULL;
-
- handle = HandlePrintStart (filename);
- if ((handle) && (PrintOneLine (handle, "\n Address Name Type Pri Lower Upper Attr\n\n"))) {
- if (! WI_Memory) {
- i = GetMemory (&entryp);
- }
- if (i) {
- for (i=0;;i++) {
- if (WI_Memory)
- DoMethod (memlist,MUIM_List_GetEntry,i,&entryp);
- if (!entryp) break;
-
- _sprintf (tmpstr2, " %s %-20.20s %-8s%4s %s %s %s\n", entryp->mem_address, entryp->mem_name, entryp->mem_type, entryp->mem_pri, entryp->mem_lower, entryp->mem_upper, entryp->mem_attributes);
- if (! (PrintOneLine (handle, tmpstr2)))
- break;
-
- if (! WI_Memory)
- entryp = entryp->mem_next;
- }
- }
- }
- HandlePrintStop();
- }
-
- void ShowMemory (void) {
- struct MemoEntry *memo;
-
- ApplicationSleep();
- set (memlist,MUIA_List_Quiet,TRUE);
- set (BT_MemPriority, MUIA_Disabled, TRUE);
- set (BT_MemMore, MUIA_Disabled, TRUE);
-
- FreeMemory();
- GetMemory (&memo);
-
- while (memo) {
- InsertBottomEntry (memlist, (APTR *) &memo);
- memo = memo->mem_next;
- }
-
- AwakeApplication();
- set (memlist,MUIA_List_Quiet,FALSE);
- }
-
- void SendMemList (void) {
- struct MemoEntry *memo;
-
- FreeMemory();
- GetMemory (&memo);
-
- while (memo) {
- SendEncodedEntry ((UBYTE *) memo, sizeof (struct MemoEntry));
- memo = memo->mem_next;
- }
- FreeMemory();
- }
-
- __asm __saveds LONG memmore_dspfunc(register __a2 char **array, register __a1 struct HunkEntry *hunkentry, register __a0 struct Hook *hook)
- {
- if (hunkentry) {
- *array++ = hunkentry->he_lower;
- *array++ = hunkentry->he_upper;
- *array++ = hunkentry->he_size;
- *array = NULL;
- } else {
- *array++ = ESC "bStart";
- *array++ = ESC "bEnd";
- *array++ = ESC "bSize";
- *array = NULL;
- }
- return (0);
- }
-
- struct Hook memmore_dsphook = {
- {NULL, NULL},
- (ULONG (* )())memmore_dspfunc,
- NULL, NULL
- };
-
-
- void GetChunkList (struct MemHeader *mem) {
- #define mementryanzahl 20
-
- struct HunkEntry *hunkentry,*chunkmem;
- struct MemChunk *first,*chunk;
- ULONG size;
- int count = 0;
-
- set(memmorelist,MUIA_List_Quiet,TRUE);
-
- if (first = mem->mh_First) {
-
- chunk = first;
- while (chunk) {
- count++;
- chunk = chunk->mc_Next;
- }
- count += 10;
-
- if (chunkmem = tbAllocPooled(MemPool, count * sizeof(struct HunkEntry))) {
-
- chunk = first;
- hunkentry = chunkmem;
- while ((count) && (chunk)) {
- size = chunk->mc_Bytes;
- _sprintf (hunkentry->he_lower, "$%08lx", chunk);
- _sprintf (hunkentry->he_size, "%8ld", size);
- _sprintf (hunkentry->he_upper, "$%08lx", ((char *) chunk) + size);
-
- InsertBottomEntry (memmorelist, (APTR *) &hunkentry);
-
- hunkentry += 1;
- chunk = chunk->mc_Next;
- count--;
- }
- }
- }
- set(memmorelist,MUIA_List_Quiet,FALSE);
- }
-
- void GetMemTypeToTmpstr (ULONG attributes) {
- int i=0;
-
- ULONG memtype[] = { MEMF_PUBLIC,MEMF_CHIP,MEMF_FAST,
- MEMF_LOCAL,MEMF_24BITDMA,MEMF_KICK,
- MEMF_CLEAR,MEMF_LARGEST,MEMF_REVERSE,MEMF_TOTAL,
- MEMF_ANY };
-
- char *memtext[] = { "PUBLIC","CHIP","FAST",
- "LOCAL","24BITDMA","KICK",
- "CLEAR","LARGEST","REVERSE","TOTAL" };
-
- tmpstr[0] = '\0';
- while (memtype[i]) {
- if (attributes & memtype[i]) {
- if (strlen (tmpstr))
- strcat (tmpstr, ", ");
- strcat (tmpstr, memtext[i]);
- }
- i++;
- }
- if (!attributes)
- strcpy (tmpstr, "ANY");
- }
-
- void GetMemMore (struct MemHeader *mem) {
- int total, inuse;
-
- unsigned char *title = "MEMORY: ";
- struct WinFree *ptr;
-
- if (ptr = AllocWinFree()) {
- ptr->wf_Window = (APTR) WindowObject,
-
- // MUIA_Window_SizeGadget, FALSE,
- MUIA_HelpNode, MemoryText,
- MUIA_Window_ID, MakeDetailID('.','M','E','M'),
- WindowContents, HGroup,
- Child, VGroup, MUIA_Group_SameWidth, TRUE,
- Child, MyLabel2 ("Name:"),
- Child, MyLabel2 ("Address:\nPri:\nType:\nFree:\nLargest:"),
- Child, MyLabel2 ("Attributes:"),
- Child, MyLabel2 ("\nChunks:"),
- Child, MyVSpace(0),
- End,
- Child, VGroup, MUIA_Group_SameWidth, TRUE,
- Child, memmoretext0 = MyTextObject(),
- Child, HGroup,
- Child, memmoretext1 = MyTextObject2(),
- Child, MyLabel ("First:\nLower:\nUpper:\nInUse:\nTotal:"),
- Child, memmoretext2 = MyTextObject2(),
- End,
- Child, memmoretext3 = MyTextObject(),
- Child, memmorelist = ListviewObject,
- MUIA_Listview_DoubleClick, TRUE,
- MUIA_Listview_Input, FALSE,
- MUIA_Listview_List, ListObject,
- MUIA_List_Format, "COL=0 DELTA=8,COL=1 DELTA=8,COL=2 P=\33r",
- // MUIA_List_AdjustWidth, TRUE,
- MUIA_List_Title, TRUE,
- MUIA_List_DisplayHook, &memmore_dsphook,
- ReadListFrame,
- End,
- MUIA_CycleChain, TRUE,
- End,
- End,
- End, End;
-
- total = ((int) mem->mh_Upper) - ((int) mem->mh_Lower);
- inuse = total - ((int) mem->mh_Free);
-
- if (ptr->wf_Window) {
- GetChunkList(mem);
-
- MySetContents (memmoretext1, ESC "r$%08lx\n" ESC "c%ld\n%s\n" ESC "r%ld\n%ld", mem, mem->mh_Node.ln_Pri, GetNodeType (mem->mh_Node.ln_Type), mem->mh_Free, AvailMem (MEMF_LARGEST | mem->mh_Attributes));
- MySetContents (memmoretext2, ESC "r$%08lx\n$%08lx\n$%08lx\n%ld\n%ld", mem->mh_First, mem->mh_Lower, mem->mh_Upper, inuse, total);
-
- GetMemTypeToTmpstr ((ULONG) mem->mh_Attributes);
- set (memmoretext3, MUIA_Text_Contents, tmpstr);
-
- HandleWindowOpen (ptr, title, nonetest (mem->mh_Node.ln_Name));
- set (ptr->wf_Window,MUIA_Window_ActiveObject,memmorelist);
- set (memmoretext0, MUIA_Text_Contents, nonetest (mem->mh_Node.ln_Name));
- HandleWindowClose (ptr);
- }
- }
- }
-
-
- char memory_title[WINDOWTITLELEN];
-
- void MemoryWindow (BOOL state) {
- if (state) {
- if (WI_Memory) {
- ShowMemory();
- } else {
- WI_Memory = WindowObject,
- MUIA_Window_Title, MyGetWindowTitle (memory_title, "MEMORY"),
- MUIA_HelpNode, MemoryText,
- MUIA_Window_ID, MakeListID('M','E','M','O'),
- WindowContents, VGroup,
- Child, memlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5 DELTA=8,COL=6",&memlist_dsphook),
- Child, memtext = MyTextObject(),
- Child, MyVSpace(2),
- Child, HGroup, MUIA_Group_SameSize, TRUE,
- Child, BT_MemPrint = KeyButtonA (PrintText ,ID_MEMPRINT),
- Child, BT_MemPriority = KeyButtonA (PriorityText,ID_MEMPRIORITY),
- Child, BT_MemMore = KeyButtonA (MoreText ,ID_MEMMORE),
- Child, BT_MemExit = KeyButtonA (ExitText ,ID_MEMEXIT),
- End,
- End, End;
-
- DoMethod (AP_Scout,OM_ADDMEMBER,WI_Memory);
- DoMethod (WI_Memory,MUIM_Window_SetCycleChain,memlist,BT_MemPrint,BT_MemPriority,BT_MemMore,BT_MemExit,NULL);
-
- SetCloseRequest (WI_Memory,ID_MEMEXIT);
- SetListActive (memlist,ID_MEMLV_ACTIVE);
- SetListviewDoubleClick (memlist,ID_MEMMORE);
-
- ShowMemory();
-
- SetWindowOpen (WI_Memory,memlist,ID_MEMEXIT);
- }
- } else if ((! state) && (WI_Memory)) {
- SetWindowClose (WI_Memory,TRUE);
-
- FreeMemory();
-
- DoMethod (AP_Scout,OM_REMMEMBER,WI_Memory);
- MUI_DisposeObject (WI_Memory);
- WI_Memory = NULL;
- memlist = NULL;
- }
- }
-
-